home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
nn.zip
/
DATE_REG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-06-28
|
1KB
|
75 lines
/*
* produce input for nngoback
*
* generates a regular expression for egrep that will
* match the last N days, execute egrep with this pattern
* and output a sequence of "group-name article" pairs
*/
#include "config.h"
#include <time.h>
#define DAYS * 24 * 60 * 60
main(argc, argv)
int argc;
char **argv;
{
time_t now, then;
struct tm *tm, *localtime();
int then_year, then_month, then_day;
int first;
if (argc != 2) {
fprintf(stderr, "usage: nngoback1 <days>\n");
exit(1);
}
time(&now);
then = now - (atoi(argv[1]) DAYS);
tm = localtime(&then);
then_year = tm->tm_year;
then_month = tm->tm_mon;
then_day = tm->tm_mday;
tm = localtime(&now);
printf("\t(");
first = 0;
while (tm->tm_year > then_year) {
printf("%s%02d", first == 0 ? "../../(" : "|", tm->tm_year);
first = 1;
tm->tm_year--;
tm->tm_mon = 11;
tm->tm_mday = 31;
}
if (first == 1) putchar(')');
while (tm->tm_mon > then_month) {
printf(first == 0 ? "(" : first == 1 ? "|(" : "|");
first = 2;
printf("%02d", tm->tm_mon + 1);
tm->tm_mon --;
tm->tm_mday = 31;
}
if (first == 2) printf(")/../%02d", then_year);
while (tm->tm_mday >= then_day) {
if (first != 0)
printf("|");
if (first != 3)
printf("%02d/(", then_month + 1);
first = 3;
printf("%02d", tm->tm_mday);
tm->tm_mday--;
}
if (first == 3) printf(")/%02d", then_year);
printf(")\n");
exit(0);
}